using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Data.SqlClient;

using SIS.ENT;

/// <summary>
/// The EmployeeOtherSkillsTableDB class is responsible for interacting with the database to retrieve and store information
/// about EmployeeOtherSkillsTable objects.
/// </summary>
public class EmployeeOtherSkillsTableDB

{
#region "Public Methods"

/// <summary>
/// Gets an instance of EmployeeOtherSkillsTable from the underlying datasource.
/// </summary>
/// <param name="employeeOtherSkillsKey">The unique EmployeeOtherSkillsKey of the EmployeeOtherSkillsTable in the database.</param>
/// <returns>An EmployeeOtherSkillsTable when the EmployeeOtherSkillsKey was found in the database, or null otherwise.</returns>
public static EmployeeOtherSkillsTable GetItem(int employeeOtherSkillsKey)
{
EmployeeOtherSkillsTable myEmployeeOtherSkillsTable = null;
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand("sprocEmployeeOtherSkillsTableSelectSingleItem", myConnection))
{
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.AddWithValue("@employeeOtherSkillsKey", employeeOtherSkillsKey);

myConnection.Open();
using (SqlDataReader myReader = myCommand.ExecuteReader())
{
if (myReader.Read()) {
myEmployeeOtherSkillsTable = FillDataRecord(myReader);
}
myReader.Close();
}
myConnection.Close();
}
return myEmployeeOtherSkillsTable;
}
}

/// <summary>
/// Returns a list with EmployeeOtherSkillsTable objects.
/// </summary>
/// <returns>A generics List with the EmployeeOtherSkillsTable objects.</returns>
public static EmployeeOtherSkillsTableList GetList()
{
EmployeeOtherSkillsTableList tempList = new EmployeeOtherSkillsTableList();
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand("sprocEmployeeOtherSkillsTableSelectList", myConnection))
{
myCommand.CommandType = CommandType.StoredProcedure;

myConnection.Open();
using (SqlDataReader myReader = myCommand.ExecuteReader())
{
if (myReader.HasRows)
{
while (myReader.Read())
{
tempList.Add(FillDataRecord(myReader));
}
}
myReader.Close();
}
}
}
return tempList;
}

/// <summary>
/// Returns a list with EmployeeOtherSkillsTable objects.
/// </summary>
/// <returns>A generics List with the EmployeeOtherSkillsTable objects.</returns>
public static EmployeeOtherSkillsTableList GetListByUserAccountKey(int UserAccountKey)
{
EmployeeOtherSkillsTableList tempList = new EmployeeOtherSkillsTableList();
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand("sprocEmployeeOtherSkillsTableSelectListByUserAccountKey", myConnection))
{
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.AddWithValue("@userAccountKey", UserAccountKey);
myConnection.Open();
using (SqlDataReader myReader = myCommand.ExecuteReader())
{
if (myReader.HasRows)
{
while (myReader.Read())
{
tempList.Add(FillDataRecord(myReader));
}
}
myReader.Close();
}
}
return tempList;
}
}

/// <summary>
/// Saves a EmployeeOtherSkillsTable in the database.
/// </summary>
/// <param name="myEmployeeOtherSkillsTable">The EmployeeOtherSkillsTable instance to save.</param>
/// <returns>The new EmployeeOtherSkillsKey if the EmployeeOtherSkillsTable is new in the database or the existing EmployeeOtherSkillsKey when an item was updated.</returns>
public static int Save(EmployeeOtherSkillsTable myEmployeeOtherSkillsTable)
{
int result = 0;
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand("sprocEmployeeOtherSkillsTableInsertUpdateSingleItem", myConnection))
{
myCommand.CommandType = CommandType.StoredProcedure;

if (myEmployeeOtherSkillsTable.EmployeeOtherSkillsKey == -1)
{myCommand.Parameters.AddWithValue("@employeeOtherSkillsKey", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@employeeOtherSkillsKey", myEmployeeOtherSkillsTable.EmployeeOtherSkillsKey);
}
if (myEmployeeOtherSkillsTable.UserAccountKey == null){
myCommand.Parameters.AddWithValue("@userAccountKey", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@userAccountKey", myEmployeeOtherSkillsTable.UserAccountKey);
}
if (myEmployeeOtherSkillsTable.SkillName == null){
myCommand.Parameters.AddWithValue("@skillName", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@skillName", myEmployeeOtherSkillsTable.SkillName);
}
if (myEmployeeOtherSkillsTable.Organization == null){
myCommand.Parameters.AddWithValue("@organization", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@organization", myEmployeeOtherSkillsTable.Organization);
}
if (myEmployeeOtherSkillsTable.NoOfYear == null){
myCommand.Parameters.AddWithValue("@noOfYear", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@noOfYear", myEmployeeOtherSkillsTable.NoOfYear);
}
if (myEmployeeOtherSkillsTable.SkillLevel == null){
myCommand.Parameters.AddWithValue("@skillLevel", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@skillLevel", myEmployeeOtherSkillsTable.SkillLevel);
}
if (myEmployeeOtherSkillsTable.Others == null){
myCommand.Parameters.AddWithValue("@others", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@others", myEmployeeOtherSkillsTable.Others);
}
if (myEmployeeOtherSkillsTable.Status == null){
myCommand.Parameters.AddWithValue("@status", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@status", myEmployeeOtherSkillsTable.Status);
}
if (myEmployeeOtherSkillsTable.CreatedDateTime == null){
myCommand.Parameters.AddWithValue("@createdDateTime", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@createdDateTime", myEmployeeOtherSkillsTable.CreatedDateTime);
}
if (myEmployeeOtherSkillsTable.ModifiedDateTime == null){
myCommand.Parameters.AddWithValue("@modifiedDateTime", DBNull.Value);
}
else
{
myCommand.Parameters.AddWithValue("@modifiedDateTime", myEmployeeOtherSkillsTable.ModifiedDateTime);
}

DbParameter returnValue;
returnValue = myCommand.CreateParameter();
returnValue.Direction = ParameterDirection.ReturnValue;
myCommand.Parameters.Add(returnValue);

myConnection.Open();
myCommand.ExecuteNonQuery();
result = Convert.ToInt32(returnValue.Value);
myConnection.Close();
}
}
return result;
}

/// <summary>
/// Deletes a EmployeeOtherSkillsTable from the database.
/// </summary>
/// <param name="employeeOtherSkillsKey">The EmployeeOtherSkillsKey of the EmployeeOtherSkillsTable to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
public static bool Delete(int employeeOtherSkillsKey)
{
int result = 0;
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["sis.dbconn"].ConnectionString))
{
using (SqlCommand myCommand = new SqlCommand("sprocEmployeeOtherSkillsTableDeleteSingleItem", myConnection))
{
myCommand.CommandType = CommandType.StoredProcedure;

myCommand.Parameters.AddWithValue("@employeeOtherSkillsKey", employeeOtherSkillsKey);
myConnection.Open();
result = myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
return result > 0;
}

#endregion

/// <summary>
/// Initializes a new instance of the EmployeeOtherSkillsTable class and fills it with the data fom the IDataRecord.
/// </summary>
private static EmployeeOtherSkillsTable FillDataRecord(IDataRecord myDataRecord )
{
EmployeeOtherSkillsTable myEmployeeOtherSkillsTable = new EmployeeOtherSkillsTable();
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("EmployeeOtherSkillsKey")))
{
myEmployeeOtherSkillsTable.EmployeeOtherSkillsKey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("EmployeeOtherSkillsKey"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("UserAccountKey")))
{
myEmployeeOtherSkillsTable.UserAccountKey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("UserAccountKey"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("SkillName")))
{
myEmployeeOtherSkillsTable.SkillName = myDataRecord.GetString(myDataRecord.GetOrdinal("SkillName"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Organization")))
{
myEmployeeOtherSkillsTable.Organization = myDataRecord.GetString(myDataRecord.GetOrdinal("Organization"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("NoOfYear")))
{
myEmployeeOtherSkillsTable.NoOfYear = myDataRecord.GetString(myDataRecord.GetOrdinal("NoOfYear"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("SkillLevel")))
{
myEmployeeOtherSkillsTable.SkillLevel = myDataRecord.GetString(myDataRecord.GetOrdinal("SkillLevel"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Others")))
{
myEmployeeOtherSkillsTable.Others = myDataRecord.GetString(myDataRecord.GetOrdinal("Others"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Status")))
{
myEmployeeOtherSkillsTable.Status = myDataRecord.GetInt16(myDataRecord.GetOrdinal("Status"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("CreatedDateTime")))
{
myEmployeeOtherSkillsTable.CreatedDateTime = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("CreatedDateTime"));
}
if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("ModifiedDateTime")))
{
myEmployeeOtherSkillsTable.ModifiedDateTime = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("ModifiedDateTime"));
}
return myEmployeeOtherSkillsTable;
}
 
}
